package com.hamu.mapper;

import com.hamu.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    //新增
    @Insert("insert into category(category_name,create_user,create_time) " +
            "values(#{categoryName},#{createUser},#{createTime})")
    void add(Category category);

    //查询所有
    @Select("select * from category where create_user=#{userId}")
    List<Category> list(Integer userId);

    List<Category> listAll();

    //根据id查询
    @Select("select * from category where id = #{id}")
    Category findById(Integer id);

    //更新
    @Update("update category set category_name=#{categoryName} where id = #{id}")
    void update(Category category);

    //删除
    @Delete("delete from category where id=#{id}")
    void delete(Integer id);

//    @Select("SELECT c.category_name, COUNT(a.id) AS article_count " +
//            "FROM category c LEFT JOIN articles a ON c.id = a.category_id " +
//            "GROUP BY c.id")
//    List<Category> getCategoryArticleCount();
}
